/*! \file Paths_pc.cpp
 *	\brief 
 *
 *	created:	2010/07/27
 *	created:	27:7:2010   18:37
 *	filename: 	C:\src\tactics-engine\libs\utils\Paths_pc.cpp
 *	file path:	C:\src\tactics-engine\libs\utils
 *	file base:	Paths_pc
 *	file ext:	cpp
 *	author:		Vitalii Trubchaninov
 *				venngraydog@gmail.com
 */
#include "utils/stdafx.h"
#include "utils/Paths.h"

#include "core/assert.h"
#include "io/StdFileSystem.h"

namespace tt{
namespace utils{

namespace impl{

io::PathW appPath()
{
	CharW buffer[MAX_PATH] = {0};
	DWORD len = GetModuleFileNameW(NULL, buffer, MAX_PATH);
	ttAssert(len != 0 && GetLastError() == ERROR_SUCCESS );
	buffer[len] = 0;

	io::PathW result(buffer);
	result = result.GetParentPath();
	return result;
}

io::PathW resourcesPath()
{
	for (io::PathW parentPath = appPath(); !parentPath.Empty(); parentPath = parentPath.GetParentPath())
	{
		io::PathW result = parentPath / L"data";
		if(ttDefaultFileSystem().IsExists( io::ToAnsi(result) ))
			return result;
	}
	ttThrow("Resources path not found!!");
	return io::PathW();
}

} //namespace impl

io::PathW appPath()
{
	static io::PathW s_appPath = impl::appPath();
	return s_appPath;
}

io::PathW resourcesPath()
{
	static io::PathW s_resourcesPath = impl::resourcesPath();
	return s_resourcesPath;
}

} //namespace utils
} //namespace tt